<?php

namespace app\admin\controller;

use think\Db;
use think\Controller;
use lib\Tool;
use think\Request;
use app\common\model\Category;
use app\common\model\Article;
use app\admin\controller\AcomController;

class CategoryController extends AcomController
{
    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete()
    {
        $id = input('post.id/d', '');
        if (Category::where('pid', $id)->find())  ajaxReturn('该分类下有子分类，无法删除分类');
        if (Article::where('c_id', $id)->find()) ajaxReturn('该分类下有文章，无法删除分类');
        if(Category::destroy($id, true)){
            ajaxReturn('',1);
        }else{
            ajaxReturn();
        }
    }
}
